SpaceToBatch ================= 将输入在空间维度按照 block_size 分块并重新排列到 batch 维度,同时根据 paddings 执行必要的零填充。 输入: - **input** - 输入数据地址。 - **block_size** - 分块因子,格式为 ``[block_h, block_w]``。 - **paddings** - 填充参数,格式为 ``[top, bottom, left, right]``。 - **input_shape** - 输入形状,格式为 ``[batch, height, width, channel]``。 - **data_size** - 单个元素字节数(例如 sizeof(float))。 - **core_mask(int, 可选)** - 核掩码(仅适用于共享存储版本)。 输出: - **output** - 输出数据地址。 支持平台: ``FT78NE`` ``MT7004`` .. note:: - FT78NE 支持的数据类型: fp32、fp64、cplx64、cplx128、int16、int8、int32。 - MT7004 支持的数据类型: fp32、fp16、cplx64、int16、int32。 **共享存储版本:** .. c:function:: void i8_spacetobatch_s(int8_t *input, int8_t *output, const int *block_size, const int *paddings, const int *input_shape, int data_size, int core_mask) .. c:function:: void i16_spacetobatch_s(int16_t *input, int16_t *output, const int *block_size, const int *paddings, const int *input_shape, int data_size, int core_mask) .. c:function:: void i32_spacetobatch_s(int32_t *input, int32_t *output, const int *block_size, const int *paddings, const int *input_shape, int data_size, int core_mask) .. c:function:: void hp_spacetobatch_s(half *input, half *output, const int *block_size, const int *paddings, const int *input_shape, int data_size, int core_mask) .. c:function:: void fp_spacetobatch_s(float *input, float *output, const int *block_size, const int *paddings, const int *input_shape, int data_size, int core_mask) .. c:function:: void dp_spacetobatch_s(double *input, double *output, const int *block_size, const int *paddings, const int *input_shape, int data_size, int core_mask) .. c:function:: void c64_spacetobatch_s(float *input, float *output, const int *block_size, const int *paddings, const int *input_shape, int data_size, int core_mask) .. c:function:: void c128_spacetobatch_s(double *input, double *output, const int *block_size, const int *paddings, const int *input_shape, int data_size, int core_mask) **C 调用示例:** .. code-block:: c :linenos: :emphasize-lines: 11 // FT78NE 多核示例 #include int main(int argc, char *argv[]) { float *input = (float *)0xA0000000; // 输入在 DDR 地址 0xA0000000 float *output = (float *)0xB0000000; // 输出在 DDR 地址 0xB0000000 int block_size[2] = {2, 2}; int paddings[4] = {0, 0, 0, 0}; int input_shape[4] = {1, 100, 10, 10}; int core_mask = 0xff; fp_spacetobatch_s(input, output, block_size, paddings, input_shape, sizeof(float), core_mask); return 0; } **私有存储版本:** .. c:function:: void i8_spacetobatch_p(int8_t *input, int8_t *output, const int *block_size, const int *paddings, const int *input_shape, int data_size) .. c:function:: void i16_spacetobatch_p(int16_t *input, int16_t *output, const int *block_size, const int *paddings, const int *input_shape, int data_size) .. c:function:: void i32_spacetobatch_p(int32_t *input, int32_t *output, const int *block_size, const int *paddings, const int *input_shape, int data_size) .. c:function:: void hp_spacetobatch_p(half *input, half *output, const int *block_size, const int *paddings, const int *input_shape, int data_size) .. c:function:: void fp_spacetobatch_p(float *input, float *output, const int *block_size, const int *paddings, const int *input_shape, int data_size) .. c:function:: void dp_spacetobatch_p(double *input, double *output, const int *block_size, const int *paddings, const int *input_shape, int data_size) .. c:function:: void c64_spacetobatch_p(float *input, float *output, const int *block_size, const int *paddings, const int *input_shape, int data_size) .. c:function:: void c128_spacetobatch_p(double *input, double *output, const int *block_size, const int *paddings, const int *input_shape, int data_size) **C 调用示例:** .. code-block:: c :linenos: :emphasize-lines: 10 // FT78NE 单核示例 #include int main(int argc, char *argv[]) { float *input = (float *)0x10000000; // 单核版本:输入放在 L2 地址 0x10000000 float *output = (float *)0x10040000; // 单核版本:输出放在 L2 地址 0x10040000 int block_size[2] = {2, 2}; int paddings[4] = {0, 0, 0, 0}; int input_shape[4] = {1, 100, 10, 10}; fp_spacetobatch_p(input, output, block_size, paddings, input_shape, sizeof(float)); return 0; }